/*
 * Copyright (C), 2002-2016, 苏宁易购电子商务有限公司
 * FileName: LoginApi.java
 * Author:   admin
 * Date:     2016年1月11日 下午12:04:20
 * Description: //模块目的、功能描述      
 * History: //修改记录
 * <author>      <time>      <version>    <desc>
 * 修改人姓名             修改时间            版本号                  描述
 */
package com.suning.app.snpaasadmin.api;

import com.suning.app.snpaasadmin.exception.BoshException;
import com.suning.app.snpaasadmin.util.HttpClientResponse;
import com.suning.app.snpaasadmin.util.HttpClientUtil;
import com.suning.app.snpaasadmin.util.HttpStatusUtil;
import com.suning.app.snpaasadmin.util.JsonUtil;

import java.util.Map;

import org.apache.http.HttpHost;
import org.apache.http.protocol.HttpContext;

/**
 * 〈一句话功能简述〉<br> 
 * 〈功能详细描述〉
 *
 * @author admin
 * @see [相关类/方法]（可选）
 * @since [产品/模块版本] （可选）
 */
public class LoginApi {
    
    public static Map<String, Object> CheckLogin(HttpContext httpContext, HttpHost httpHost) throws Exception {
        String urlPath = httpHost.toString()+"/info";
        HttpClientResponse response = HttpClientUtil.doGet(urlPath, null, null, httpHost, httpContext);
        if (!HttpStatusUtil.isSuccessStatus(response.getStatus())) {
            String content = response.getBody();
            Map<String, Object> data = JsonUtil.convertJsonToMap(content);
            throw new BoshException(String.valueOf(response.getStatus()), data.get("description").toString());
        }
        String content = response.getBody();
        return JsonUtil.convertJsonToMap(content);
    }

}
